package db;

import java.sql.ResultSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
//import java.util.HashMap;

import core.City;
import core.Continent;
import core.Country;
import core.Group;
import core.QuestionLog;
import core.User;
//import parsing.Category;
//import parsing.Person;

public abstract class DB_Abstract {

	// ################### DB
	// ####################################################
	public static LinkedList<City> cities = new LinkedList<City>();
	public static LinkedList<Continent> continents = new LinkedList<Continent>();
	public static LinkedList<Country> countries = new LinkedList<Country>();	
	public static LinkedList<User> users = new LinkedList<User>();
	//public static LinkedList<Category> categories = new LinkedList<Category>();
	//public static Map<String, Person> persons = new HashMap<String, Person>();

	// ################### Connections Functions
	// ###################################

	public int connect() {
		return 1;
	}

	public int closeConnection() {
		return 1;
	}

	// ################### Add Data Functions
	// ###################################

	// #####BASICS######

	public int addNewContinent(Continent newContinent) {
		return 0;
	}

	public int addNewCountry(Country newCountry) {
		return 0;
	}

	public int addNewCity(City newCity) {
		return 0;
	}



	public int addNewCategory(String CatName) {
		return 0;
	}

	public int addNewUser(User user) {
		return 0;
	}

	public int addNewGroup(Group group) {
		return 0;
	}

	public int addUserToGroup(int userID, int groupID) {
		return 0;
	}

	// ##### COMBINATIONS ######

	public int addNewCityFromList(LinkedList<City> cities) {
		return 0;
	}

	public int addUserToGroup(User user, int groupID) {
		return addUserToGroup(user.getID(), groupID);
	}

	public int addUserToGroup(User user, Group group) {
		return addUserToGroup(user.getID(), group.getId());
	}

	public int addUserToGroup(int userID, Group group) {
		return addUserToGroup(userID, group.getId());
	}

	// ################### Remove Data Functions
	// ###################################

	// #####BASICS######
	public int removeCountry(int countryID) {
		return 0;
	}

	public int removeCategory(int catID) {
		return 0;
	}

	public int removeCity(int cityID) {
		return 0;
	}

	public int removeUser(int userID) {
		return 0;
	}

	public int removeGroup(int groupID) {
		return 0;
	}

	public int removeUserFromGroup(int userID, int groupID) {
		return 0;
	}

	// ##### COMBINATIONS ######

	// ###Remove Country

	public int removeCountry(Country count) {
		return removeCountry(count.getCountryId());
	}

	public int removeCity(City city) {
		return removeCountry(city.getCityId());
	}

	public int removeUser(User user) {
		return removeUser(user.getID());
	}

	public int removeGroup(Group group) {
		return removeGroup(group.getId());
	}

	public int removeUserFromGroup(User user, int groupID) {
		return removeUserFromGroup(user.getID(), groupID);
	}

	public int removeUserFromGroup(User user, Group group) {
		return removeUserFromGroup(user.getID(), group.getId());
	}

	public int removeUserFromGroup(int userID, Group group) {
		return removeUserFromGroup(userID, group.getId());
	}

	// #################### Modify Data Functions
	// ####################################

	// #####BASICS######

	public int modifyCountry(Country Cat, String newName) {
		// Assume can only Modify a category name
		return 0;
	}

	public int modifyCategory(int catID, String newName) {
		return 0;
	}

	public int modifyCity(int cityID, String newName) {
		return 0;
	}

	public int modifyCityLong(float longitude, int cityId) {
		return 0;
	}

	public int modifyCityLat(float latitude, int cityId) {
		return 0;
	}

	public int modifyUser(String OldUserName, User newUser) {
		return 0;
	}

	public int modifyGroup(int oldGroupID, Group newGroup) {
		return 0;
	}

	public int modifyUserInGroup(int userID, int groupID, int newScore) {
		return 0;
	}

	// Advanced Functions

	public int modifyCity(City city, String newName) {
		return modifyCity(city.getCityId(), newName);
	}

	public int modifyGroup(Group oldGroup, Group newGroup) {
		return modifyGroup(oldGroup.getId(), newGroup);
	}

	public int modifyUserInGroup(User user, int groupID, int newScore) {
		return modifyUserInGroup(user.getID(), groupID, newScore);
	}

	public int modifyUserInGroup(User user, Group group, int newScore) {
		return modifyUserInGroup(user.getID(), group.getId(), newScore);
	}

	public int modifyUserInGroup(int userID, Group group, int newScore) {
		return modifyUserInGroup(userID, group.getId(), newScore);
	}

	// #################### Get Data Functions
	// ####################################

	// #####BASICS######

	public City getCity(int cityID) {
		return null;
	}


	public Country getCountry(int countryID) {
		return null;
	}

	public Continent getContinent(int continentID) {
		return null;
	}

	public User getUser(int userID) {
		return null;
	}

	public User getUser(String userName) {
		return null;
	}

	public Group getGroup(int groupID) {
		return null;
	}

	public int getUserScoreInGroup(int userID, int groupID) {
		return -1;
	}

	public LinkedList<Group> getGroupsInUser(int userID) {
		return null;
	}

	public LinkedList<User> getUsersInGroupSorted(int groupID) {
		return null;
	}

	public LinkedList<Group> getGroups() {
		return null;
	}

	public LinkedList<Country> getCountriesSorted() {
		return null;
	}

	// ##### COMBINATIONS ######

	// ###Get Continent

	public Continent getContinent(City city) {
		return getContinent(getCountry(city));
	}

	public Continent getContinent(Country country) {
		return getContinent(country.getContinentId());
	}

	public Continent getContinent(String ContinentName) {
		return null;
	}

	// ###Get Country

	public Country getCountry(City city) {
		return getCountry(city.getCountryId());
	}
	
	public Country getCountry(String countryName) {
		return null;
	}

	// ###Get User

	public User getUser(User user) {
		return getUser(user.getName());
	}

	// ####UserInGroup

	public int getUserScoreInGroup(User user, int groupID) {
		return getUserScoreInGroup(user.getScore(), groupID);
	}

	public int getUserScoreInGroup(User user, Group group) {
		return getUserScoreInGroup(user.getScore(), group.getId());
	}

	public int getUserScoreInGroup(int userID, Group group) {
		return getUserScoreInGroup(userID, group.getId());
	}

	public LinkedList<Group> getGroupsInUser(User user) {
		return getGroupsInUser(user.getID());
	}

	public LinkedList<User> getUsersInGroupSorted(Group group) {
		return getUsersInGroupSorted(group.getId());
	}

	// ##### ADVANCED ######

	// To Implement
	public LinkedList<City> getCitiesFromCountry(int countryID) {
		return null;
	}

	// Not to be implemented
	public LinkedList<City> getCities(Country country) {
		return getCitiesFromCountry(country.getCountryId());
	}

	// ################## SQL Functions ####################
	public ResultSet execQuery(String query) {
		return null;
	}

	public int execUpdate(String update) {
		return 1;
	}

	public int execStatment(java.sql.Statement stmt) {
		return 1;
	}

	public java.sql.Statement getStmt() {
		return null;
	}

	public int updateFromFile(String filePath) {
		return 1;
	}

	public int updateFromString(String query) {
		return 1;

	}

	public int removeFieldByID(String tableName, String fieldName, int ID) {

		return 1;

	}

	// ################### Setters and Getters
	// ###################################

	public LinkedList<City> getCities() {
		return cities;
	}

	public static void setCities(LinkedList<City> cities) {
		DB_Abstract.cities = cities;
	}

	public LinkedList<Continent> getContinents() {
		return continents;
	}

	public static void setContinents(LinkedList<Continent> continents) {
		DB_Abstract.continents = continents;
	}

	public static LinkedList<Country> getCountries() {
		return countries;
	}

	public static void setCountries(LinkedList<Country> countries) {
		DB_Abstract.countries = countries;
	}

	public int HashSample(String str) {
		int hash = 7;
		for (int i = 0; i < str.length(); i++) {
			hash = hash * 31 + str.charAt(i);
		}
		return hash;
	}

	public List<City> getRandomCities(int numOfQuestions) {
		// returns a list of random numOfQuestions cities
		return null;
	}

	// returns a list of numOfQuestions cities from continent contID
	public List<City> getCitiesByContinent(int contID, int numOfQuestions) {
		return null;
	}

	// returns a list of numOfQuestions cities from country countryID
	public List<City> getCitiesByCountry(int countryID, int numOfQuestions) {
		return null;
	}

	public int addNewQuestion(int user_id, int group_id, int city_id,
			int score, int seconds, long time) {
		return 1;
	}

	public LinkedList<Continent> getAllContinents() {
		return null;
	}

	public LinkedList<Group> createGroupsFromRSWithScore(ResultSet rs) {
		return null;
	}


	public int updateGeoTables(String continentsCountriesFile,

	String citiesFile, boolean flag, String workspacePath){
		return 0;
	}
	public int updateContinentsTable(LinkedList<Continent> continents) {
		return 0;
	}

	public int updateCountriesTable(Map<String, Country> countries) {
		return 0;
	}

	public int updateCitiesTable(String citiesFile) {
		return 0;
	}

	public LinkedList<QuestionLog> createQuestionsFromRS(ResultSet rs) {
		return null;
	}

	public LinkedList<QuestionLog> getQuestionsByUser(int user_id) {
		return null;
	}

	
	public int createUpdateCitiesTable(String filepath){
	return 0;
	}

	public int updateAndOverrideCitiesTable(String fileName) {
		return 0;
	}

	public int OverrideUpdate() {
		return 0;
	}

	public int updateWithnoOverride() {
		return 0;
	}
	public int dropUpdatesTable(){
		return 0;
	}
	
	
	//### DEPRECATED
	//##############
	
//	// ###Get CITY
//	// ###Get Category
//	
//	//###Persons stuff###
	
//	public int addNewPersonFromList(Map<String, Person> persons) {
//		return 0;
//	}
//	
//	public int addNewPerson(Person newPerson) {
//		return 0;
//	}
//	
//	public int removePerson(Person per) {
//		return 0;
//	}
//	
//	public int modifyPerson(Person oldPer, Person newPer) {
//		return 0;
//	}
//	
//	public Person getPerson(int ID) {
//		return null;
//	}
//
//	public Person getPerson(String name) {
//		return null;
//	}
//	
//	public Continent getContinent(Person per, int index) {
//		// index 1 = Birth City
//		// index 2 = Death City
//		return getContinent(getCountry(per, index));
//	}
//
//	public Continent getContinent(String person_Name, int index) {
//		// index 1 = Birth City
//		// index 2 = Death City
//		Person per = getPerson(person_Name);
//		return getContinent(per, index);
//	}
//	
//	public Country getCountry(Person per, int index) {
//		// index 1 = Birth City
//		// index 2 = Death City
//		return getCountry(getCity(per, index));
//	}
//
//	public Country getCountry(String person_Name, int index) {
//		Person per = getPerson(person_Name);
//		return getCountry(per, index);
//	}
//
//	public City getCity(Person per, int index) {
//		// index 1 = Birth City
//		// index 2 = Death City
//
//		if (index == 1)
//			return getCity(per.getBirthCityID());
//
//		if (index == 2)
//			return getCity(per.getDeathCityID());
//
//		return new City("-1", -1, -1, -1, -1);
//	}
//
//	public City getCity(String person_Name, int index) {
//		Person per = getPerson(person_Name);
//		return getCity(per, index);
//	}
//
//	public LinkedList<Category> getCategory(String personName) {
//		Person per = getPerson(personName);
//		return getCategory(per);
//
//	}
//
//	public LinkedList<Category> getCategory(Person per) {
//
//		return getCategory(per.getCategories());
//
//	}
//	
//	public static Map<String, Person> getPersons() {
//		return persons;
//	}
//
//	public static void setPersons(Map<String, Person> persons) {
//		DB_Abstract.persons = persons;
//	}
	
//	//###Category Stuff###
//	
//	public int removeCategory(Category cat) {
//		return removeCountry(cat.getCategoryID());
//	}
//	
//	public int modifyCategory(Category Cat, String newName) {
//		return modifyCategory(Cat.getCategoryID(), newName);
//	}
//	
//	public LinkedList<Category> getCategory(List<Integer> list) {
//		LinkedList<Category> categoryList = new LinkedList<Category>();
//		for (int i = 0; i < list.size(); i++) {
//			categoryList.add(getCategory(list.get(i)));
//		}
//
//		return categoryList;
//	}
//	
//	public Category getCategory(int CategoryID) {
//		return null;
//	}
//	
//	public static LinkedList<Category> getCategories() {
//		return categories;
//	}
//
//	public static void setCategories(LinkedList<Category> categories) {
//		DB_Abstract.categories = categories;
//	}
	
}
